package speedball.popup;

import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.Node;
import javafx.scene.control.RadioButton;
import javafx.scene.control.Toggle;
import javafx.scene.control.ToggleGroup;
import javafx.scene.paint.Color;
import javafx.scene.shape.Shape;

import java.net.URL;
import java.util.ResourceBundle;

public class ShowPopupController implements Initializable {


    private Shape parentShape;

    @FXML
    private RadioButton commonMode;
    @FXML
    private RadioButton gameMode;
    @FXML
    private RadioButton ramValue;
    @FXML
    private RadioButton intellectValue;
    @FXML
    private RadioButton defaultShow;
    @FXML
    private RadioButton internetSpeedShow;
    @FXML
    private RadioButton CPUTemperatureShow;
    @FXML
    private RadioButton carouselShow;


    @Override
    public void initialize(URL location, ResourceBundle resources) {
        final ToggleGroup modeGroup = new ToggleGroup();
        final ToggleGroup valueGroup = new ToggleGroup();
        final ToggleGroup showGroup = new ToggleGroup();
        commonMode.setToggleGroup(modeGroup);
        gameMode.setToggleGroup(modeGroup);
        commonMode.setSelected(true);
        commonMode.setUserData("common");
        gameMode.setUserData("game");


        ramValue.setToggleGroup(valueGroup);
        intellectValue.setToggleGroup(valueGroup);
        ramValue.setSelected(true);
        ramValue.setUserData("ram");
        intellectValue.setUserData("intellect");

        defaultShow.setToggleGroup(showGroup);
        internetSpeedShow.setToggleGroup(showGroup);
        CPUTemperatureShow.setToggleGroup(showGroup);
        carouselShow.setToggleGroup(showGroup);
        defaultShow.setSelected(true);

        defaultShow.setUserData("default");
        internetSpeedShow.setUserData("internetSpeed");
        CPUTemperatureShow.setUserData("CPUTemperature");
        carouselShow.setUserData("carousel");

        modeGroup.selectedToggleProperty().addListener(new ChangeListener<Toggle>(){
            public void changed(ObservableValue<? extends Toggle> ov,
                                Toggle old_toggle, Toggle new_toggle) {
                if (modeGroup.getSelectedToggle() != null) {
                    if(modeGroup.getSelectedToggle().getUserData().equals("game")){
                        parentShape.setFill(Color.BLACK);
                    }else if(modeGroup.getSelectedToggle().getUserData().equals("common")){
                        parentShape.setFill(Color.rgb(245, 245, 245));
                    }
                    System.out.println(modeGroup.getSelectedToggle().getUserData());
                }
            }
        });


        valueGroup.selectedToggleProperty().addListener(new ChangeListener<Toggle>(){
            public void changed(ObservableValue<? extends Toggle> ov,
                                Toggle old_toggle, Toggle new_toggle) {
                if (valueGroup.getSelectedToggle() != null) {
                    System.out.println(valueGroup.getSelectedToggle().getUserData());
                }
            }
        });

        showGroup.selectedToggleProperty().addListener(new ChangeListener<Toggle>(){
            public void changed(ObservableValue<? extends Toggle> ov,
                                Toggle old_toggle, Toggle new_toggle) {
                if (showGroup.getSelectedToggle() != null) {
                    System.out.println(showGroup.getSelectedToggle().getUserData());
                }
            }
        });



    }

    public RadioButton getCommonMode() {
        return commonMode;
    }

    public void setCommonMode(RadioButton commonMode) {
        this.commonMode = commonMode;
    }

    public RadioButton getGameMode() {
        return gameMode;
    }

    public void setGameMode(RadioButton gameMode) {
        this.gameMode = gameMode;
    }

    public RadioButton getRamValue() {
        return ramValue;
    }

    public void setRamValue(RadioButton ramValue) {
        this.ramValue = ramValue;
    }

    public RadioButton getIntellectValue() {
        return intellectValue;
    }

    public void setIntellectValue(RadioButton intellectValue) {
        this.intellectValue = intellectValue;
    }

    public RadioButton getDefaultShow() {
        return defaultShow;
    }

    public void setDefaultShow(RadioButton defaultShow) {
        this.defaultShow = defaultShow;
    }

    public RadioButton getInternetSpeedShow() {
        return internetSpeedShow;
    }

    public void setInternetSpeedShow(RadioButton internetSpeedShow) {
        this.internetSpeedShow = internetSpeedShow;
    }

    public RadioButton getCPUTemperatureShow() {
        return CPUTemperatureShow;
    }

    public void setCPUTemperatureShow(RadioButton CPUTemperatureShow) {
        this.CPUTemperatureShow = CPUTemperatureShow;
    }

    public RadioButton getCarouselShow() {
        return carouselShow;
    }

    public void setCarouselShow(RadioButton carouselShow) {
        this.carouselShow = carouselShow;
    }

    public Shape getParentShape() {
        return parentShape;
    }

    public void setParentShape(Shape parentShape) {
        this.parentShape = parentShape;
    }
}
